package com.kin.rich.dao;

import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.kin.rich.pojo.Countresult;

/**
 * A data access object (DAO) providing persistence and search support for
 * Countresult entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.kin.rich.pojo.Countresult
 * @author MyEclipse Persistence Tools
 */

public class CountresultDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(CountresultDAO.class);
	// property constants
	public static final String WORD_ID = "wordId";
	public static final String GOOD_COUNT = "goodCount";
	public static final String BAD_COUNT = "badCount";
	public static final String MIDDLE_COUNT = "middleCount";
	public static final String START_PAGE = "startPage";
	public static final String END_PAGE = "endPage";
	public static final String COUNT_TIMES = "countTimes";

	protected void initDao() {
		// do nothing
	}

	public void save(Countresult transientInstance) {
		log.debug("saving Countresult instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Countresult persistentInstance) {
		log.debug("deleting Countresult instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Countresult findById(java.lang.Integer id) {
		log.debug("getting Countresult instance with id: " + id);
		try {
			Countresult instance = (Countresult) getHibernateTemplate().get(
					"com.kin.rich.pojo.Countresult", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Countresult instance) {
		log.debug("finding Countresult instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Countresult instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Countresult as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByWordId(Object wordId) {
		return findByProperty(WORD_ID, wordId);
	}

	public List findByGoodCount(Object goodCount) {
		return findByProperty(GOOD_COUNT, goodCount);
	}

	public List findByBadCount(Object badCount) {
		return findByProperty(BAD_COUNT, badCount);
	}

	public List findByMiddleCount(Object middleCount) {
		return findByProperty(MIDDLE_COUNT, middleCount);
	}

	public List findByStartPage(Object startPage) {
		return findByProperty(START_PAGE, startPage);
	}

	public List findByEndPage(Object endPage) {
		return findByProperty(END_PAGE, endPage);
	}

	public List findByCountTimes(Object countTimes) {
		return findByProperty(COUNT_TIMES, countTimes);
	}

	public List findAll() {
		log.debug("finding all Countresult instances");
		try {
			String queryString = "from Countresult";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Countresult merge(Countresult detachedInstance) {
		log.debug("merging Countresult instance");
		try {
			Countresult result = (Countresult) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Countresult instance) {
		log.debug("attaching dirty Countresult instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Countresult instance) {
		log.debug("attaching clean Countresult instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static CountresultDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (CountresultDAO) ctx.getBean("CountresultDAO");
	}
}